#include <bits/stdc++.h>
#include <string>
using namespace std;

int k, n, house[100001];

int getMaxReduceLen(int l)
{
	// dp维护最长递减子序列  dp_2维护最长递增子序列
	int dp[100001] = {1}, dp_2[100001] = {1}, maxx = -INT_MAX, maxy = -INT_MAX;
	for (int i = 1; i < l; i++)
	{
		for (int j = 0; j < i; j++)
		{
			if (house[i] < house[j])
				dp[i] = max(dp[i], dp[j] + 1);
			if (house[i] > house[j])
				dp_2[i] = max(dp_2[i], dp_2[j] + 1);
		}
		maxx = max(maxx, dp[i]);
		maxy = max(maxy, dp_2[i]);
	}
	return max(maxx, maxy);
}

int main()
{
	cin >> k;
	while (k--)
	{
		cin >> n;
		for (int i = 0; i < n; i++)
			cin >> house[i];
		cout << getMaxReduceLen(n) << endl;
	}

	return 0;
}